import { useState, useEffect } from "react"
function App() {
  const [count, setCount] = useState(0)
  const [num, setNum] = useState(20)

  useEffect(() => {
    // console.log('useEffect');

    // const timer = setInterval(() => {
    //   setCount(count + 1)
    // }, 1000) // 这会出bug

    // 在组件卸载时触发
    // return () => {
    //   console.log('卸载了');
    //   clearInterval(timer)
    // }

  }, [count])  // 只有当后面的[]中的值变更了才执行
  

  const add = () => {
    setCount(count + 1)
    // setNum(num + 1)
  }

  return (
    <button onClick={add}>{count}</button>
  )
}

export default App